
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None
    
class Solution:
    def deleteNode(self, head: ListNode, val: int) -> ListNode:
        if head is None:
            return None
        if head.val == val:
            return head.next
        
        a,b = head,head.next
        while b.val!=val:
            a = b
            b = b.next
        a.next = b.next
        return head